<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>公司管理</el-breadcrumb-item>
      <el-breadcrumb-item>公司列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <p style="font-size:20px;font-weight:500">公司信息</p>
    <el-table
      :data="list"
      style="width: 100%">
      <el-table-column prop="ename" label="公司名称"></el-table-column>
      <el-table-column prop="etype" label="公司类型"></el-table-column>
      <el-table-column prop="status" label="状态码"></el-table-column>
      <el-table-column label="状态" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0" effect="dark" type="info">未审核</el-tag>
          <el-tag v-else effect="dark" type="success">已审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="warning" size="small" @click="update(scope.row)">查看</el-button>
          <el-button v-if="scope.row.status == 0" size="small" @click="frame(scope.row,1)">通过审核</el-button>
          <el-button v-else size="small" type="danger" @click="frame(scope.row,0)">取消审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="page"
      :total="total"
      :page-size="pageSize"
      @current-change="goPage">
    </el-pagination>
  </div>
</template>

<script>

export default {
  data(){
    return {
      page: 1,
      total: 100,
      pageSize: 8,
      /* list: [
        {
          ename: '1',
          etype: '互联网',
          status: '0'
        },
        {
          ename: '222',
          etype: '教育',
          status: '0'
        },
        {
          ename: '333',
          etype: '电商',
          status: '0'
        },
      ] */
      list: [],
      status: 0,
      stu: ''
    }
  },
  created(){
    this.status = this.$route.params.status;
    this.getData()
  },
  watch: {
    
  },
  methods: {
    getData(){
      this.$http({
        url: '/admin/Enterprise/getAll',
        params: {
          page: this.page,
          pageSize:this.pageSize
        }
      }).then(res => {
        this.list = res
      })
    },
    goPage(page){
      this.page = page
      this.getData()
    },
    update(scope){
      console.log(scope);
      this.$router.push({
        path: '/company/detail',
        query: {
          eid: scope.eid
        }
      })
    },
    frame(scope, status) {
      console.log(status);
      if (status == 1) {
        this.stu = "通过审核";
      } else {
        this.stu = "取消审核";
      }
      this.$confirm(`确定要${this.stu}吗？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        //切换审核状态
        this.$http({
          url: "admin/Enterprise/update",
          params: {
            eid: scope.eid,
            status
          },
        }).then((res) => {
          this.getData();
          this.$message({
            type: res.integer == 1 ? "error" : "success",
            message: '修改审核状态成功',
          });
          if (res.integer == 1) {
            this.getData();
          }
        });
      })
      .catch(() => {});
    },
  }
}
</script>

<style scoped>
.el-table{
  margin-bottom: 20px;
}
</style>